package com.xique.door.project.sfm.utils;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


public class SfmHttpTool {

    public static String doPost(String url, String json) {
        HttpPost post = new HttpPost(url);
        String response = null;
        try {
             StringEntity s = new StringEntity(json, "UTF-8"); // 中文乱码在此解决
             s.setContentType("application/json");
             post.setEntity(s);
             HttpResponse res = HttpClients.createDefault().execute(post);
             if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                  String result = EntityUtils.toString(res.getEntity());// 返回json格式：
                  response =result;
             }
        } catch (Exception e) {
             e.printStackTrace();
        }
        return response;
  }
    
    
}
